package zozopo.oa;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.operations.oa.OutlayOS;
import zozopo.operations.oa.OutlayTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;

public class AddOutlayAction  extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String limitedCode ="OA.OUTLAY.ADD";
	
	private Map<Object, Object> session;
	
	//传入参数
	private String kind_outlay;
	private double total_outlay;
	private String remark_outlay;
	
	
	//传出参数
	private OutlayTB outlay;
	
	public String execute(){
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
		
		
		OutlayOS outlayOS = new OutlayOS();
		
		outlay = new OutlayTB();
		outlay.setKind_outlay(kind_outlay);
		outlay.setRemark_outlay(remark_outlay);
		outlay.setTotal_outlay(total_outlay);
		outlay.setUseremail_outlay(operator.getEmail_operator());
		outlay.setUsername_outlay(operator.getName_operator());
		
		if(!outlayOS.insert(outlay)){
			return ERROR;
		}
		
		outlay = outlayOS.getNew(operator.getEmail_operator());
		
		outlayOS.releaseConnection();
		
		return SUCCESS;
	}
	public void validate() {
		
		
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户添加通讯录权限");
			return;
		}
		
		
	}
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String getKind_outlay() {
		return kind_outlay;
	}
	public void setKind_outlay(String kind_outlay) {
		this.kind_outlay = kind_outlay;
	}
	public double getTotal_outlay() {
		return total_outlay;
	}
	public void setTotal_outlay(double total_outlay) {
		this.total_outlay = total_outlay;
	}
	public String getRemark_outlay() {
		return remark_outlay;
	}
	public void setRemark_outlay(String remark_outlay) {
		this.remark_outlay = remark_outlay;
	}
	public OutlayTB getOutlay() {
		return outlay;
	}
	public void setOutlay(OutlayTB outlay) {
		this.outlay = outlay;
	}
	public static String getLimitedcode() {
		return limitedCode;
	}


}
